import {Config} from '../../utils/conf.js';
import {httpReq} from '../../utils/http.js';
// 小程序提供引入方式
var WxParse = require("../../wxParse/wxParse.js");


class info
{
  getList(that,qid){
    let obj = {};
    obj.url = Config.getoneansurl + qid;
    httpReq(obj).then(res=>{
      //获取对应的评论
      // let comd = { url: Config.getcom + res.data.data.id}
      // httpReq(comd).then(res => {
      //   if(res.data.data.length > 0){
      //     var ss = false;
      //   }
      //   that.setData({
      //     comments: res.data.data,
      //     comshow: ss
      //   })
      // })
      this.getcom(that,res.data.data.id);
      // 富文本的解决插件
      WxParse.wxParse("videohtml", "html", res.data.data.answer, that, 5);
      that.setData({
        row: res.data.data,
        aid: res.data.data.id
      })
    })
  }

  //提交函数
  saveinfo(that,aid, comment) {
    let obj = {};
    obj.url = Config.savecom;
    obj.method = 'post';
    obj.data = {
      uid:wx.getStorageSync('uid'),
      aid,
      com_body:comment
    };
    httpReq(obj).then(res => {
        if(res.data.state == 0){
          that.setData({
            com: ''
          })
          wx.showToast({
            title: '评论成功',
            icon: 'success',
          })
          this.getcom(that,aid);
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
          })
        }
    })
  }

  //获取指定答案
  getans(that,aid){
    let obj = {};
    obj.url = Config.getoneans + aid;
    httpReq(obj).then(res => {
      //获取对应的评论
      let comd = { url: Config.getcom + res.data.data.id }
      httpReq(comd).then(res => {
        if (res.data.data.length > 0) {
          var ss = false;
        }
        that.setData({
          comments: res.data.data,
          comshow: ss
        })
      })
      that.setData({
        row: res.data.data,
        aid: res.data.data.id
      })
    })
  }

  getcom (that,id) {
    let comd = { url: Config.getcom + id}
    httpReq(comd).then(res => {
      if(res.data.data.length > 0){
        var ss = false;
      }
      that.setData({
        comments: res.data.data,
        comshow: ss
      })
    })
  }
}

export default info;